package com.yxt.exception;

import java.util.List;

import com.yxt.common.sys.LocalUtil;

public abstract class AbstractException extends RuntimeException {
	private static final long serialVersionUID = 1L;
	
	String messageCode;
    String[] params;

    public AbstractException() {
    }

    public AbstractException(Throwable throwable) {
        super(throwable);
    }

    public AbstractException(String msg) {
        this(null, msg, null);
    }

    public AbstractException(String messageCode, String[] params) {
        this(null, messageCode, params);
    }

    public AbstractException(String messageCode, List<String> paramsList) {
        this(null, messageCode, paramsList.toArray(new String[0]));
    }

    public AbstractException(Throwable cause, String messageCode,
                             String[] params) {
        this(cause);
        this.messageCode = messageCode;
        this.params = params;
    }

    /* (non-Javadoc)
     * @see java.lang.Throwable#getMessage()
     */
    @Override
    public String getMessage() {
        StringBuilder buff = new StringBuilder();

        Throwable cause = getCause();

        if (cause != null) {
            buff.append(cause.getMessage());
            buff.append("\r\n");
        }

        if (messageCode != null) {
            String mess = LocalUtil.getMessage(messageCode);
            
            if (mess != null) {
                buff.append(mess);
            } else {
                buff.append(messageCode);
            }
        }

        return buff.toString();
    }
}